package Function;

import FCRendering.FCRMaster;
import FCRendering.azer.PlayerAction;
import VWorldGameStudio.*;
import VWorldGameStudio.events.BattleEvent;
import lombok.Getter;
import socket.FCRSocketClient;
import socket.FCRSocketServer;
import socket.util.ByteUtil;
import socket.util.SLog;
import sun.awt.windows.ThemeReader;
import utils.FCMixUtil;
import utils.entity.BigTankPack;
import utils.entity.MsgPack;
import utils.entity.RandomPack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.BiConsumer;

import static FCRendering.FCRMaster.*;
import static FCRendering.FCRMaster.eventLib;

//游戏缓存
public class FCMutilPlayCache {
    //TODO 意思是只能跟3个人，1+3 = 4，因为战斗图问题，最多允许4个人
    public static final int MAX_TEAM_MEMBERS = 3;
    /**
     * 组队链队头名称
     */
    public static FCRPlayerLink teamLink = null;
    //队尾
    public static FCRPlayerLink teamLinkEnd = null;

    /**
     * 队伍跟随的人数
     */
    @Getter
    public static Vector<FCRPlayerLink> teamMembers = new Vector<>();

    /**
     * 所有包括其他玩家的集合
     * 为了快速方便查找，改成map
     * key= hostId+name
     */
    public static ConcurrentHashMap<String, FCPlayerInfo> gamePlayers = new ConcurrentHashMap<>();


    //地图场景
    public static HashMap<String, ArrayList<String>> multiDoors = new HashMap<>();

    /**
     * 在所有的playerInfo里查找
     *
     * @param hostUid
     * @param name
     * @return
     */
    public static FCPlayerInfo findPlayerByName(String hostUid, String name) {
        if (FCRMaster.player1.getName().equals(name) && FCRMaster.player1.getAliasUID().equals(hostUid)) {
            return FCRMaster.player1;
        }
        return gamePlayers.get(hostUid + name);
    }

    public static FCPlayerInfo findPlayerByHostId(String hostUid) {
        if (FCRMaster.player1.getAliasUID().equals(hostUid)) {
            return FCRMaster.player1;
        }
        ArrayList<FCPlayerInfo> find = new ArrayList<>();
        gamePlayers.forEach(new BiConsumer<String, FCPlayerInfo>() {
            @Override
            public void accept(String s, FCPlayerInfo playerInfo) {
                if (playerInfo.getAliasUID().equals(hostUid)) {
                    find.add(playerInfo);
                }
            }
        });
        return find.size()>0?find.get(0):null;
    }

    /**
     * 表示除了player1的以外所有的角色都放进来
     *
     * @param playerInfo
     */
    public static void joinGame(FCPlayerInfo playerInfo) {
        if (playerInfo != null) {
            FCPlayerInfo find = findPlayerByName(playerInfo.getAliasUID(), playerInfo.getName());
            if (find != null) {
                gamePlayers.remove(find.getAliasUID()+find.getName());
            }
            gamePlayers.put(playerInfo.getAliasUID()+playerInfo.getName(), playerInfo);
            SLog.getInstance().e_s("玩家 " + playerInfo.getAliasUID() + "-" + playerInfo.getChName() + " 连接上了");
        }
    }

    //退出
    public static void quitGame(FCPlayerInfo playerInfo) {
        if (playerInfo != null) {
            FCPlayerInfo find = findPlayerByName(playerInfo.getAliasUID(), playerInfo.getName());
            if (find != null) {
                gamePlayers.remove(find);
            }
        }
    }

    public static void delAllFCPlayerInfoByHostId(String host) {
        //删除所有的角色
        ArrayList<FCPlayerInfo> removes = new ArrayList<>(0);
        gamePlayers.forEach(new BiConsumer<String, FCPlayerInfo>() {
            @Override
            public void accept(String s, FCPlayerInfo playerInfo) {
                if (playerInfo.getAliasUID().equals(host)) {
                    if (playerInfo.getPlayertank1() != null && !playerInfo.getPlayertank1().equals("null")) {
                        if (!playerInfo.getPlayertankHostId().equals(host)) {
                            //TODO 不是他的坦克，要可见留下来
                            FCTank tank = tankLib.getTankOfID(playerInfo.getPlayertank1(), playerInfo.getPlayertankHostId());
                            if (tank != null) {
                                tank.setVisable(1);
                            }
                        }
                    }
                    removes.add(playerInfo);
                }
            }
        });
        for(FCPlayerInfo p: removes) {
            gamePlayers.remove(p.getAliasUID()+p.getName());
        }
    }

    public static void battleEnd() {
        delAllFCPlayerInfoByHostId("npc");
        FCMutilPlayTankCache.delAllTanksByHostId("npc");
    }

    private static void parseMovingData(long rTime, byte[] params, int offset, String map, String uid, String name) {
        FCPlayerInfo playerInfo1 = findPlayerByName(uid, name);
        long lastSyncTime = FCMutilPlayTimeSyncHelper.getInstance().getLastSyncTime(uid + name + "#moving");
        if (playerInfo1 != null && rTime >= lastSyncTime) {
            FCMutilPlayTimeSyncHelper.getInstance().saveNewSyncTime(uid + name + "#moving", rTime);
            int oldCoodX = playerInfo1.getPlayer1x();
            int oldCoodY = playerInfo1.getPlayer1y();
            int x = ByteUtil.getInt(new byte[]{params[0 + offset], params[1 + offset], params[2 + offset], params[3 + offset]});
            int y = ByteUtil.getInt(new byte[]{params[4 + offset], params[5 + offset], params[6 + offset], params[7 + offset]});
            playerInfo1.setMapname(map);
            playerInfo1.setPlayer1x(x);
            playerInfo1.setPlayer1y(y);
            int ox = ByteUtil.getInt(new byte[]{params[8 + offset], params[9 + offset], params[10 + offset], params[11 + offset]});
            int oy = ByteUtil.getInt(new byte[]{params[12 + offset], params[13 + offset], params[14 + offset], params[15 + offset]});
            playerInfo1.setPianYiXFromRemote(ox);
            playerInfo1.setPianYiYFromRemote(oy);
            int d = ByteUtil.getInt(new byte[]{params[16 + offset], params[17 + offset], params[18 + offset], params[19 + offset]});
            int a = ByteUtil.getInt(new byte[]{params[20 + offset], params[21 + offset], params[22 + offset], params[23 + offset]});
            playerInfo1.setActionDir(d);
            playerInfo1.setActionNumFromRemote(a);

            int lx = ByteUtil.getInt(new byte[]{params[24 + offset], params[25 + offset], params[26 + offset], params[27 + offset]});
            int ly = ByteUtil.getInt(new byte[]{params[28 + offset], params[29 + offset], params[30 + offset], params[31 + offset]});
            playerInfo1.setLastInWorldMapX(lx);
            playerInfo1.setLastInWorldMapY(ly);
            if (fcv.isInTeamLink()) {
                if (player1.getName().equals(playerInfo1.getName())) {
                    if (oldCoodX != playerInfo1.getPlayer1x() || oldCoodY != playerInfo1.getPlayer1y()) {
                        gameSave.addStepCount();//加步数
                        PlayerAction.getInstance().stepChangeAndCheckLongTermState();
                        //TODO 有移动了，坦克位置更新和同步给别人
                        fcrMaster.movingSetTank();
                        if (fcv.isSever()) {
                            FCRSocketServer.getIn().syncYouTankMoving();
                        } else if (fcv.isClient()) {
                            FCRSocketClient.getIn().syncYouTankMoving();
                        }
                    }
                }
                //要是被控制的玩家对象，那就记录下吧
                playerInfo1.recordAndSetUpPianyi();
                fcv.setDirDown(false);
                fcv.setDirUp(false);
                fcv.setDirLeft(false);
                fcv.setDirRight(false);
            } else if (fcv.getBindingPlayerName() != null && fcv.getBindingPlayerName().equals(playerInfo1.getName())) {
                //TODO 不在队伍里
                if (playerInfo1.getAliasUID().equals(fcv.getBindingPlayerHostId())) {
                    int playerX = player1.getPlayer1x();
                    int playerY = player1.getPlayer1y();
                    //TODO 对了，跟随着走了
                    player1.setPlayer1x(playerInfo1.getPlayer1x());
                    player1.setPlayer1y(playerInfo1.getPlayer1y());
                    player1.setPianYiX(playerInfo1.getPianYiX());
                    player1.setPianYiY(playerInfo1.getPianYiY());
                    player1.setActionNum(playerInfo1.getActionNum());
                    player1.setActionDir(playerInfo1.getActionDir());
                    player1.recordAndSetUpPianyi();
                    player1.disPatchActionNum(FCMutilPlayCache.teamLink, player1.getActionNum());
                    if (FCRMaster.fcv.isSever()) {
                        FCRSocketServer.getIn().playerMoving();
                    } else if (FCRMaster.fcv.isClient()) {
                        FCRSocketClient.getIn().playerMoving();
                    }
                    if (playerX != player1.getPlayer1x() || playerY != player1.getPlayer1y()) {
                        //移动格了
                        fcrMaster.flowmoving(false);
                        player1.setMapname(playerInfo1.getMapname());
                    }
                }
            }
        } else {
            System.out.println("时间落后了 " + rTime);
        }
    }

    //：n个Player+{Player.x+Player.y+Player.pianYiX+Player.pianYiY+Player.dir+Player.num}+MapName+HOSTUI+Player.Names
    public static void updateMoving(long rTime, byte[] params) {
        try {

            int playerInfoCounts = params[0] & 0xFF;
            byte[] wrapbytes = new byte[params.length - (1 + playerInfoCounts * 32)];
            System.arraycopy(params, 1 + playerInfoCounts * 32, wrapbytes, 0, wrapbytes.length);
            String wrapstr = new String(wrapbytes);
            String[] splits1 = wrapstr.split(",");
            String mapName = splits1[0];
            String[] splits2 = splits1[1].split("@");
            Vector<String> hostUid = new Vector<>();
            Vector<String> names = new Vector<>();
            for (int i = 0; i < splits2.length; i++) {
                String[] split3 = splits2[i].split("#");
                hostUid.add(split3[0]);
                names.add(split3[1]);
            }
            for (int i = 0; i < playerInfoCounts; i++) {
                parseMovingData(rTime, params, 1 + 32 * i, mapName, hostUid.get(i), names.get(i));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void updateJoinInTeam(byte[] params, String[] splits) {
        //int playerInfoCounts = params[0]& 0xFF;
        fcv.setTeamReqeuestFromWho(splits[0]);
        for (int i = 2; i < splits.length; i += 2) {
            FCPlayerInfo fcPlayerInfo = findPlayerByName(splits[i], splits[i + 1]);
            if (fcPlayerInfo != null) {
                FCRMaster.player1.joinInTeam(fcPlayerInfo);
            }
        }
    }


    //有人请求组队
    public static boolean getRequestTeam(byte[] params, String[] split) {
        if (fcv.isShowTeamRequest()) {
            //TODO 已经有组队申请了，就不要再处理了，拒绝对方

            return false;
        }
        if (fcv.isInTeamLink()) {
            //TODO 已经有组队了，就不要再处理了
            return false;
        }
        int flag = params[0] & 0xFF;
        if (flag == 1) {
            //TODO 想你加入对方
        } else {
            //TODO 对方想加入你
        }
        fcv.setTeamReqeuestFromWho(split[0]);
        fcv.setTeamRequestWay(flag);
        fcv.setShowTeamRequest(true);
        return true;
    }

    //对方回复了
    public static void getRequestTeamRepo(byte[] params, String[] splits) {
        if (params[0] == 1) {
            //TODO 答应你了，傻猪
            if (params[1] == 0) {
                //加进去
                if (fcv.isClient()) {
                    FCRSocketClient.getIn().playerJoinIn();
                } else {
                    FCRSocketServer.getIn().playerJoinIn();
                }
            }
        } else {
            System.out.println("对方拒绝了你的组队请求！");
            fcv.getMessage().add("对方拒绝了你的组队请求！");
            fcv.showMessage();
        }
        fcv.setLockClickPlayerHost(false);//解锁
    }

    //有人要退队了
    public static void getTeamJoinOut(byte[] params, String[] splits) {
        if (params[0] == 1) {
            //TODO 我是队长，收到了xx的退队消息，那就只清除他就行了
            removeOtherInTeamNetPlayers(splits[0]);
            //TODO 移除掉别的玩家的牵引物
            FCRMaster.player1.removeRemotePropulsion(splits[0]);
        } else if (params[0] == 0) {
            //TODO 队长退队了，解散队伍了，各自清楚状态等
            fcv.setInTeamLink(false);
            //TODO 如果有牵引物，就要重整一下
            fcv.setTeamLeader(null);
        }
        FCRMaster.player1.resetPropulsionIfNeed();
    }

    public static void aPlayerExitGame(String hostId) {
        //队伍里移除
        FCMutilPlayCache.removeOtherInTeamNetPlayers(hostId);
        //TODO 移除掉别的玩家的牵引物
        FCRMaster.player1.removeRemotePropulsion(hostId);
        FCMutilPlayCache.delAllFCPlayerInfoByHostId(hostId);
        FCMutilPlayPropulsionCache.fromNetNoShareIt(hostId);
        FCMutilPlayTankCache.delAllTanksByHostId(hostId);
        FCMutilPlayCache.delSyncTeamScreenByHost(hostId);
        FCPlayerInfo checkPlayer = player1;
        for (int i = -1; i < FCMutilPlayCache.getTeamMembers().size(); i++) {
            if (i == -1) {
            } else {
                FCRPlayerLink link = FCMutilPlayCache.getTeamMembers().get(i);
                checkPlayer = FCMutilPlayCache.findPlayerByName(link.curPlayerHostUID, link.curPlayerName);
            }
            if (checkPlayer.getAliasUID().equals(gameSave.HOST_UID)) {
                if (checkPlayer.getPlayertank1() != null && !checkPlayer.getPlayertank1().equals("null")) {
                    if (checkPlayer.getPlayertankHostId().equals(hostId)) {
                        checkPlayer.setPlayertank1("null");
                        checkPlayer.setPlayertankHostId("null");
                        //TODO 直接下车
                    }
                }
            }
        }
        //TODO 如果这个人是队长呢？,队伍解散了，自由了
        if (fcv.getTeamLeader() != null && fcv.getTeamLeader().equals(hostId)) {
            fcv.setTeamLeader(null);
            //就是在别人的队咯，要通知对方把你移除队伍里
            fcv.setInTeamLink(false);
            //TODO 如果有牵引物，就要重整一下
            FCRMaster.player1.resetPropulsionIfNeed();
        }
        if (fcv.isLockClickPlayerHost() && hostId.equals(fcv.getCurTeamMenuClickPlayerHost())) {
            fcv.setLockClickPlayerHost(false);
            fcv.getMessage().add("申请组队的玩家已经离开了游戏！");
            fcv.showMessage();
        }
    }

    /**
     * TODO
     * 这里属于队伍断开后，全部其他玩家都清掉的情况
     */
    public static void removeOtherInTeamNetPlayers(String hostId) {
        Vector<FCRPlayerLink> fcrPlayerLinks = new Vector<>();
        for (FCRPlayerLink link : FCMutilPlayCache.getTeamMembers()) {
            if (link.curPlayerHostUID.equals(hostId)) {
                fcrPlayerLinks.add(link);
            }
        }
        for (FCRPlayerLink link : fcrPlayerLinks) {
            FCPlayerInfo p = FCMutilPlayCache.findPlayerByName(link.curPlayerHostUID, link.curPlayerName);
            FCRMaster.player1.quitTeam(p);
            //彻底退出
        }
        ArrayList<FCPlayerBattleWrap> wraps = new ArrayList<>();
        for (FCPlayerBattleWrap w : fcv.getBattleWraps()) {
            if (w.getHostUid().equals(hostId)) {
                wraps.add(w);
            }
        }
        if (wraps.size() > 0) {
            fcv.getBattleWraps().removeAll(wraps);
        }
        System.out.println("removeOtherInTeamNetPlayers size:" + getTeamMembers().size());
    }

    public static void parseJumpEvent(byte[] params) {
        //TODO 在别人队伍里才做这些处理
        if (fcv.isInTeamLink()) {
            String data = new String(params);
            String[] splits = data.split("@");

            if (FCRMaster.player1.getMapname().equals("world")) {
                FCRMaster.player1.setLastInWorldMapX(FCRMaster.player1.getPlayer1x());
                FCRMaster.player1.setLastInWorldMapY(FCRMaster.player1.getPlayer1y());
            }
            FCRMaster.player1.setMapname(splits[0]);
            FCEvent fcEvent = FCRMaster.eventLib.getEventOfName(splits[1]);
            fcv.setPlayingEvent(fcEvent);
            fcv.setJumpactionnum(0);
            //启动跳转地图
        }
    }

    public static void updateBattleWrap(FCPlayerBattleWrap wrap) {
        for (FCPlayerBattleWrap search : fcv.getBattleWraps()) {
            if (wrap.getHostUid().equals(search.getHostUid()) && wrap.getName().equals(search.getName())) {
                //只需要同步部分就行了
                search.setBattleReady(wrap.isBattleReady());
                search.setBattlePlayerSelectMenu(wrap.getBattlePlayerSelectMenu());
                search.setBattleAttackOrder(wrap.getBattleAttackOrder());
                search.setBattlePlayerSelectPlayer(wrap.getBattlePlayerSelectPlayer());
                search.setBattleUseItemType(wrap.getBattleUseItemType());
                search.setBattleDriverTank(wrap.isBattleDriverTank());
                search.setBattlePlayerSelectItem(wrap.getBattlePlayerSelectItem());
                search.setBattlePlayerSelectPaoDanIndex(wrap.getBattlePlayerSelectPaoDanIndex());
                search.setBattlePlayerSelectItemMode(wrap.getBattlePlayerSelectItemMode());
                search.setBattlePlayerSelectMonster(wrap.getBattlePlayerSelectMonster());
                break;
            }
        }
    }

    public static void updateBattleRandoms(RandomPack randomPack) {
        System.out.println("现在随机数 " + fcv.getMutilPlayRandomV().size() + " 增加随机数 " + randomPack.floatArrayList.size());
        fcv.getMutilPlayRandomV().addAll(randomPack.floatArrayList);
    }

    public static void parseSyncEquip(long receiveTime, HashMap<String, String> map) {
        String hostId = map.get("hostId");
        String name = map.get("name");
        String arm = map.get("arm");
        String pants = map.get("pants");
        String shoes = map.get("shoes");
        String hat = map.get("hat");
        String jacket = map.get("jacket");
        String glove = map.get("glove");
        FCPlayerInfo find = findPlayerByName(hostId, name);
        long time = FCMutilPlayTimeSyncHelper.getInstance().getLastSyncTime(hostId + name + "#equip");
        if (find != null && receiveTime >= time) {
            FCMutilPlayTimeSyncHelper.getInstance().saveNewSyncTime(hostId + name + "#equip", receiveTime);
            find.setArm(arm);
            find.setJacket(jacket);
            find.setPants(pants);
            find.setHat(hat);
            find.setShoes(shoes);
            find.setGlove(glove);
        }
    }

    //TODO 收到要战斗了
    public static void parseBattleStart(FCBattlePack pack) {
        FCRMaster.fcv.getBattleMonsterCoor().clear();
        FCRMaster.fcv.getBattleMonsterCoor().addAll(pack.monsterCoors);
        FCRMaster.fcv.getMutilPlayRandomV().clear();
        FCRMaster.fcv.getMutilPlayRandomV().addAll(pack.randomVs);
        FCRMaster.fcv.getBattleWraps().clear();
        FCRMaster.fcv.getBattleWraps().addAll(pack.battleWraps);
        FCRMaster.fcv.getBattleMonster().clear();
        for (String monsterId : pack.monsterId) {
            FCRMaster.fcv.getBattleMonster().add(monLib.getMonsterOfID(monsterId).getClone());
        }
        //step 3
        for (int i = 0; i < fcv.getBattleWraps().size(); i++) {
            FCPlayerBattleWrap playerBattleWrap = fcv.getBattleWraps().get(i);
            FCPlayerInfo p = FCMutilPlayCache.findPlayerByName(playerBattleWrap.getHostUid(), playerBattleWrap.getName());
            if (p != null) {
                FCTank a = tankLib.getTankOfID(p.getPlayertank1(), p.getPlayertankHostId());
                if (a != null) {
                    a.reInitShuxing();
                }
            }
        }
        if (pack.battleEventId != null) {
            FCEvent bEvent = eventLib.getEventOfName(pack.battleEventId);
            fcv.setBattleEvent(bEvent);
        }
        if (pack.bossRecord != null) {
            fcv.setBattleBossRecord(pack.bossRecord);
        }
        fcrMaster.fcMonsterBuildCoor.syncServiceBuildCoor(pack.buildCoorLastCoor, pack.buildCoorMaxMonsterW, pack.buildCoorLeftPadding);
        FCRMaster.eventOrderHelper.dealBattleEvent((BattleEvent) fcv.getBattleEvent(), 1);
        fcv.setFightMenuBntSelect(-1);
        fcv.setBattleRounds(1);
        fcv.setBattle(true);
        fcv.setBattleReady(true);
        defaultFightScreen.selectNextPlayer();
    }


    public static void parsePlayerUpDownTank(long receiveTime, byte[] params) {
        byte[] data = new byte[params.length - 1];
        System.arraycopy(params, 1, data, 0, params.length - 1);
        String dataStr = new String(data);
        String[] split = dataStr.split(",");
        FCPlayerInfo p = findPlayerByName(split[0], split[1]);
        long time = FCMutilPlayTimeSyncHelper.getInstance().getLastSyncTime(split[0] + split[1] + "#upDownTank");

        if (p != null && receiveTime >= time) {
            FCMutilPlayTimeSyncHelper.getInstance().saveNewSyncTime(split[0] + split[1] + "#upDownTank", receiveTime);
            if (params[0] == 1) {
                //有车
                p.setPlayertank1(split[2]);
                p.setPlayertankHostId(split[3]);
            } else {
                p.setPlayertank1("null");
                p.setPlayertankHostId("null");
            }
        }
    }

    public static void parsePlayerSyncState(long receiveTime, ArrayList<FCPlayerTransport> transports) {
        for (FCPlayerTransport port : transports) {
            FCPlayerInfo info = findPlayerByName(port.hostId, port.name);
            long time = FCMutilPlayTimeSyncHelper.getInstance().getLastSyncTime(port.hostId + port.name + "#pState");
            if (info != null && receiveTime >= time) {
                FCMutilPlayTimeSyncHelper.getInstance().saveNewSyncTime(port.hostId + port.name + "#pState", receiveTime);
                port.setUpThePlayerInfo(info);
            }
        }
    }

    public static void parseSyncTeamScreen(FCMultiSyncScreenPack pack) {
        if (pack.syncMode == 0) {
            String key = pack.mapName + "*" + pack.doorX + "*" + pack.doorY;
            ArrayList<String> whoOpenDoor = multiDoors.get(key);
            if (whoOpenDoor == null) {
                whoOpenDoor = new ArrayList<>();
                multiDoors.put(key, whoOpenDoor);
            }
            if (pack.isOpenDoor) {
                if (!whoOpenDoor.contains(pack.srcHostId)) {
                    whoOpenDoor.add(pack.srcHostId);
                }
            } else {
                whoOpenDoor.remove(pack.srcHostId);
            }
        }
    }

    public static void delSyncTeamScreenByHost(String hostId) {
        multiDoors.forEach(new BiConsumer<String, ArrayList<String>>() {
            @Override
            public void accept(String s, ArrayList<String> strings) {
                strings.remove(hostId);
            }
        });
    }

    public static void parseRemoteUpDownMyTank(byte[] param) {
        String dd = new String(param);
        String[] dsplit = dd.split(",");
        FCTank tank = tankLib.getTankOfID(dsplit[1], dsplit[0]);
        if (tank != null) {
            if (dsplit[2].equals("1")) {
                tank.setVisable(0);
            } else {
                tank.setVisable(1);
            }
        }
    }

    public static void parseRemoteMoveTank(long receiveTime, ArrayList<String> datas) {
        for (String d : datas) {
            String[] dSplit = d.split(",");
            //fcTank.getHostId()+","+fcTank.getName()+","+fcTank.getPmapname()+","+fcTank.getPcoorY()
            //                        +","+fcTank.getPcoorY()+","+fcTank.getPdir()+","+fcTank.getPactionNum()
            FCTank find = tankLib.getTankOfID(dSplit[1], dSplit[0]);
            long time = FCMutilPlayTimeSyncHelper.getInstance().getLastSyncTime(dSplit[1] + dSplit[0] + "#moveTank");
            if (find != null && receiveTime >= time) {
                FCMutilPlayTimeSyncHelper.getInstance().saveNewSyncTime(dSplit[1] + dSplit[0] + "#moveTank", receiveTime);
                find.setPmapname(dSplit[2]);
                find.setPcoorX(Integer.parseInt(dSplit[3]));
                find.setPcoorY(Integer.parseInt(dSplit[4]));
                find.setPdir(Integer.parseInt(dSplit[5]));
                find.setPactionNum(Integer.parseInt(dSplit[6]));
                find.setPPianYiX(0);
                find.setPPianYiY(0);
                FCMutilPlayPropulsionCache.shareIt(find);
            }
        }
    }

    //TODO 更新坦克上的物品内容
    public static void paraseRemoteTankItems(BigTankPack bigTankPack) {
        FCTank find = tankLib.getTankOfID(bigTankPack.tank.getName(), bigTankPack.tank.getHostId());
        FCTank tank = bigTankPack.tank;
        if (find != null) {
            find.setChassisID(tank.getChassisID());
            find.setGunID(tank.getGunID());
            find.setGun2ID(tank.getGun2ID());
            find.setSEID(tank.getSEID());
            find.setCdeviceID(tank.getCdeviceID());
            find.setRadarID(tank.getRadarID());
            find.setEngineID(tank.getEngineID());
            find.setKnapsack(tank.getKnapsack());
            find.setPmapname(tank.getPmapname());
            find.setAcidState(tank.isAcidState());
            find.setResidues(tank.getResidues());
            find.setDefense(tank.getDefense());
            find.reInitShuxing();
            bigTankPack.tankItems.forEach(new BiConsumer<String, FCItem>() {
                @Override
                public void accept(String s, FCItem fcItem) {
                    gameSave.updateOrAddTankItem(s, fcItem);
                }
            });
        }
    }

    public static void parseGetPlayerMsg(MsgPack msg) {
        FCPlayerInfo find = findPlayerByName(msg.hostId, msg.playerName);
        if (find != null) {
            find.setTalkingMsg(msg.msg);
        }
    }
}
